<dictionary_name>={key1:value1,key2:value2,...}
md1={4117:'Amit Jain',3012:'Gopal Pandey',5126:'Raja Rathi'} print(md1) md2={'name':'Amit Jain','age':23,'city':'Amravati'} print(md2)
{4117:'Amit Jain',3012:'Gopal Pandey',5126:'Raja Rathi'} {'name':'Amit Jain','age':23,'city':'Amravati'}
<dictionary_name>[key]
md={'name':'Amit Jain','marks':[52,64,73,42,63] } print(md["name"]) print(md["marks"])
Amit Jain [52, 64, 73 , 42, 63]
<dictionary_name>=dict(**kwarg)
data=dict(first_name="Amit Jain",age=31,city="Amravati") print(data)
{'first_name': 'Amit Jain', 'age': 31, 'city': 'Amravati'}
Functions | |
---|---|
clear() | Removes all elements of dictionary. |
copy() | Returns a copy of dictionary. |
get(key,default=None) | returns value of key or default if key not in dictionary. |
update(dictionary) | Adds contents of a dictionary. |
values() | Returns list of dictionary values. |
keys() | Returns list of dictionary keys. |
items() | Returns a list of (key, value) tuple pairs. |
popitem() | Returns and removes an arbitrary element (key, value) pair from the dictionary. |
pop(key) | Method removes and returns an element from a dictionary having the given key. |
dit = {'Name': 'Amit Jain', 'Age': 7,'City':'Amravati'}; for key in dit: print(key);
Name Age City
dit = {'Name': 'Amit Jain', 'Age': 7,'City':'Amravati'}; for key,val in dic.items(): print(key, " : " ,val);
Name: Amit Jain Age: 7 City: Amravati